//
// Created by dave on 18-7-31.
//

#pragma once
#include <chrono>
#include <ctime>
#include <cassandra.h>
#include "../codec/data_utils.h"
#include "../codec/data_pack.h"
#include "../codec/terminal/location_report.h"

using namespace std::chrono;

struct location {
public:
    location() = default;

    location(data_pack& report) {
        sim = report.get_sim();
        std::shared_ptr<location_report> r = std::dynamic_pointer_cast<location_report>(report.get_body());
        time = parse_time(r->get_time());
        CassUuidGen* uuid_gen = cass_uuid_gen_new();
        cass_uuid_gen_time(uuid_gen, &uuid);
        cass_uuid_gen_free(uuid_gen);

        alarm = r->get_alarm();
        flag = r->get_flag();
        located = r->is_located();
        lat = r->get_lat();
        lng = r->get_lng();
        height = r->get_height();
        speed = r->get_speed();
        direction = r->get_direction();
    }

    std::string get_sim() const { return sim; }
    void set_sim(std::string sim) { this->sim = sim; }

    CassUuid get_uuid() const { return this-> uuid; }
    void set_uuid(CassUuid uuid) { this->uuid = uuid; }

    time_t get_time() const { return time; }
    void set_time(time_t time) { this->time = time; }

    unsigned get_alarm() const { return alarm; }
    void set_alarm(unsigned alarm) { this->alarm = alarm; }

    unsigned get_flag() const { return flag; }
    void set_flag(unsigned flag) { this->flag = flag; }

    bool is_located() const { return located; }
    void set_located(bool located) { this->located = located; }

    double get_lat() const { return lat; }
    void set_lat(double lat) { this->lat = lat; }

    double get_lng() const { return lng; }
    void set_lng(double lng) { this->lng = lng; }

    int get_height() const { return height; }
    void set_height(int height) { this->height = height; }

    int get_speed() const { return speed; }
    void set_speed(int speed) { this->speed = speed; }

    int get_direction() const { return direction; }
    void set_direction(int direction) { this->direction = direction; }

private:
    std::string sim;
    CassUuid uuid;
    time_t time;
    unsigned alarm;
    unsigned flag;
    bool located;
    double lat;
    double lng;
    int height;
    int speed;
    int direction;
};